/****************************************************************************************************/
/**
\file       OS_Types.h
\brief      OS type definitions
\author     Equipo 1
\version    1.0
\date       08/03/2014
*/
/****************************************************************************************************/

#ifndef OS_TYPES_H        /*prevent duplicated includes*/ 
#define OS_TYPES_H  

/****************************************************************************************************
* Include files
*****************************************************************************************************/
/* Variable types and common definitions */
#include  "typedefs.h"
/* S12X derivative information */
#include  "mc9s12xep100.h"



typedef enum 
{
  E_OK = 0,
  E_OS_ACCESS,
  E_OS_CALLEVEL,
  E_OS_ID,
  E_OS_LIMIT,
  E_OS_NOFUNC,
  E_OS_RESOURCE,
  E_OS_STATE,
  E_OS_VALUE
}OS_StatusType;

typedef enum 
{
  TASK_SUSPENDED,
  TASK_READY,
  TASK_RUNNING,
  TASK_WAITING
}OS_TaskStateType;

typedef u16 TaskType;
typedef TaskType * TaskRefType;
typedef u8 TaskStateType;
typedef TaskStateType * TaskStateRefType;
typedef u16 TaskDeadlineType;


typedef tCallbackFunction taskFunction;


typedef struct 
{
  TaskType      id;
  void (*task_function)(void);
  u16 stackSize;
  TaskDeadlineType  relativeDeadLine;
  TaskDeadlineType  absoluteDeadLine;
  u16 mask;
  u16 offset;
  u8 priority;
}OS_TaskType;


typedef struct 
{
  u16                taskNumber;
  OS_TaskType * taskConfig;
}OS_TaskConfigType;



typedef struct 
{
  TaskType      id;
  u16           mask;
  u16           offset;
  tCallbackFunction taskfunction;
  TaskStateType taskState;
  u16           stack_startAddress;
  u16           stack_endAddress;
  TaskDeadlineType  relativeDeadLine;
  TaskDeadlineType  absoluteDeadLine;
  u8            priority;
}OS_TaskControlBlockInformationType;


typedef struct 
{
  TaskType      id;
  void (*task_function)(void);
}OS_TaskQueuedType;

typedef struct
{
  u8 queueIndex;
  u8 unqueuIndex;
  OS_TaskQueuedType *taskQueue;
}taskQueueType;

/****************************************************************************************************
* Module wide variables 
*****************************************************************************************************/

/****************************************************************************************************
* Function Prototypes
*****************************************************************************************************/

#ifndef TASK
#define TASK(taskID)          void OS_task_##taskID(void)
#define TASK_NAME(taskID)          OS_task_##taskID
#define getTask
#endif

#define DeclareTask(taskID) extern TASK(taskID)

#endif /* OS_TYPES_H */ 